package com.woniu.platform.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.woniu.platform.entity.PlatformAuditRecord;
import com.woniu.platform.entity.PlatformTenderAuditRecord;
import com.woniu.platform.entity.vo.PlatformTenderVO;
import com.woniu.platform.mapper.PlatformTenderAuditRecordMapper;
import com.woniu.platform.service.PlatformTenderAuditRecordService;
import com.woniu.util.utils.HttpResult;
import com.woniu.util.utils.RequestResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@Service
public class PlatformTenderAuditRecordServiceImpl implements PlatformTenderAuditRecordService {

    @Autowired(required = false)
    private PlatformTenderAuditRecordMapper tenderAuditRecordMapper;
    @Override
    public HttpResult insertTenderAuditRecord(PlatformTenderAuditRecord tenderAuditRecord) {
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        tenderAuditRecord.setAuditTime(dateFormat.format(new Date()));
        int re = tenderAuditRecordMapper.insert(tenderAuditRecord);
        if(re>0){
            return new HttpResult().ok();
        }else {
            return new HttpResult().fail();
        }
    }

    @Override
    public HttpResult queryTenderAuditByPage(RequestResult<PlatformTenderAuditRecord> param) {
        PageHelper.startPage(param.getPageNum(), param.getPageSize());
        List<PlatformTenderAuditRecord> list = tenderAuditRecordMapper.queryTenderAuditRecord(param.getData().getTenderId(),param.getData().getAuditResult());
        PageInfo pageInfo = new PageInfo(list);
        return new HttpResult().ok(pageInfo);
    }

    @Override
    public HttpResult queryTenderByTenderId(Integer tenderId) {
        PlatformTenderVO tender = tenderAuditRecordMapper.queryTenderById(tenderId);
        if(tender !=null){
            return new HttpResult().ok(tender);
        }else {
            return new HttpResult().fail();
        }
    }

    @Override
    public HttpResult queryTenderList(RequestResult<PlatformTenderVO> param) {
        PageHelper.startPage(param.getPageNum(),param.getPageSize());
        List<PlatformTenderVO> list = tenderAuditRecordMapper.queryTenderList(param.getData().getFinanceName(), param.getData().getCoreName());
        PageInfo pageInfo = new PageInfo(list);
        return new HttpResult().ok(pageInfo);
    }

    @Override
    public HttpResult queryTenderByFullAudit(RequestResult<PlatformTenderVO> param) {
        PageHelper.startPage(param.getPageNum(),param.getPageSize());
        List<PlatformTenderVO> list = tenderAuditRecordMapper.queryTenderByFullAudit(param.getData().getFinanceName(), param.getData().getCoreName());
        PageInfo pageInfo = new PageInfo(list);
        return new HttpResult().ok(pageInfo);
    }
}
